using CodePlex.CodePlexClientLibrary.ProjectInfoWebSvc;
using CodePlex.TfsLibrary;

namespace CodePlex.CodePlexClientLibrary
{
    public class CodePlexProjectInfoService : ICodePlexProjectInfoService
    {
        readonly ProjectInfoService webService;

        public CodePlexProjectInfoService(IAppConfig config)
        {
            webService = new ProjectInfoService(config.CodePlexWebServiceUrl);
            webService.Timeout = 15 * 60 * 1000;
        }

        public string CodePlexUsernameToTfsUsername(string username)
        {
            return webService.CodePlexUserNameToTfsUserName(username);
        }

        public string[] GetProjects(string username)
        {
            return webService.ListProjectsForUser(username);
        }

        public CodePlexTfsProjectInfo GetTfsInfoForProject(string projectName)
        {
            ProjectTfsInfo info = webService.GetTfsInfoForProject(projectName);
            return new CodePlexTfsProjectInfo(info.TfsServerUrl, info.ProjectPrefix);
        }
    }
}